//
//  ST_TIANEngagementModel.swift
//  btvideo
//
//  Created by Jason on 2021/7/30.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//


import SwiftyJSON


enum ST_EngagementType:Int{
    case voice = 1
    case video = 2
}



enum ST_EngagementStatus {
    case normal,talking,hungUp
}

//enum TIANEngagementJoinConfig {
//
//    case local(sessionId:String,value:JSON)
//
//    case remote(pulledValue:JSON,responseValue:JSON)
//
//}


struct ST_TIANEngagementConst {
    
    let rechargeSeconds:Int
    
    let waitSeconds:Int
    
    
    #if DEBUG
    static let `default` = ST_TIANEngagementConst(rechargeSeconds: 60, waitSeconds: 60)
    #else
    static let `default` = ST_TIANEngagementConst(rechargeSeconds: 60, waitSeconds: 30)
    #endif
    
}

class ST_TIANEngagementEntiy {
    
    let json:JSON
    /// 跳转路径
    let fromPath:String
    
    let chatType:ST_EngagementType
    
//    let joinConfig:TIANEngagementJoinConfig
    /// 后台字段sped_id 扣费ID
    let spentId:String
    
    let channelId:String
    
    let sessionId:String
    
    let currentId:UInt
    
    /// 接受动画
    let isReceived:Bool
    
    var remoteUserId:UInt64?
    
    var remoteCanvas:NTESDemoUserModel?
    
    init(chatType: ST_EngagementType, joinConfig: JSON,pushPathStr: String,isReceived:Bool = false){
        

        self.isReceived = isReceived
        
        self.fromPath = pushPathStr
        
        self.chatType = chatType
        
        self.json = joinConfig
//        self.joinConfig = joinConfig
        
        print("#98013 joinConfig = ",joinConfig)
        
        
        self.spentId = json["sped_id"].stringValue
        self.channelId = json["channel_name"].stringValue
        
        self.channelPrice = json["price"].floatValue
        self.channelToken = json["token"].stringValue
        
        
        self.freeTalkSeconds = json["free_time"].intValue
        
        self.impressionSeconds = json["free_count"].intValue > 0 ? 10 : 0
        self.haveImpression = self.impressionSeconds > 0
        
        if self.isReceived{
            
            self.currentId = json["uid"].uIntValue
            
            self.oppositeAvatar = json["from_avatar"].string
            
            self.oppositeNickname = json["from_nickname"].string
            
            self.sessionId = json["from_accid"].stringValue
            
        }else{
            
            /// sessionId 对方的accid 我是发起方，使用接收方id
            self.sessionId = json["receive_accid"].stringValue
            
            self.currentId = json["uid"].uIntValue
            
            self.oppositeAvatar =  json["receive_avatar"].string
            
            self.oppositeNickname = json["receive_nickname"].string
        }
        
        
        
    }
    
//    MARK: - mutable properties
    
    /// 当前频道请求ID
    var currentRequestId:String?
    
    var currentChannel:String?
    
    /// 警告次数
    var currentChannelWarningTimes = 0
    
    var freeTalkSeconds = 0
    
    /// 初体验的时间  新增需求
    var impressionSeconds = 0
    
    /// 拥有 初体验的时间  新增需求
    var haveImpression = false
    
    ///价格
    private(set) var channelPrice:Float = 0
    
    /**
     第一次提示充值
     */
    var firstToastRecharge = false
 
    
    var currentIncome:Float = 0
    
    var channelToken = ""
    
    var totalSeconds = 0
    
    /// 对面拒绝我的邀请
    var targetRefuseMe = false

    /// 对面头像
    var oppositeAvatar:String?
    /// 对面昵称
    var oppositeNickname:String?
}
